import React from 'react';
import ItemOrders from '../component/item-orders';
import {fromJS} from 'immutable';


export const orderStatusList = [{name: '所有订单', key: 'ALL'}
, {name: '待发货', key: 'WAIT_DELIVER'}, {name: '待收货', key: 'WAIT_RECEIVE'}
, {name: '已完成', key: 'SUCCESS'}, {name: '已取消', key: 'CLOSE'}];

export function renderOrderFilter(type) {
    if (type === 'unpay') {
        return [
            {name: '所有订单', key: 'UNPAY_ALL'}
            ,{name: '待支付', key: 'WAIT_PAY'}
            ,{name: '已取消', key: 'UNPAY_CLOSE'}
        ]
    }
    return [
        {name: '所有订单', key: 'ALL'}
        ,{name: '待发货', key: 'WAIT_DELIVER'}
        ,{name: '待收货', key: 'WAIT_RECEIVE'}
        ,{name: '已完成', key: 'SUCCESS'}
        ,{name: '已取消', key: 'CLOSE'}
    ]
}


export function orderColumns(type = 'sales') {
    return [
        {
            title: '商品',
            key: 'itemOrders',
            dataIndex: 'itemOrders',
            render: (itemOrders, record, index) => {
                return {
                    children: <ItemOrders itemOrders={fromJS(itemOrders)}/>,
                    props: {
                        colSpan: 2
                    }
                }
            }
        },
        {
            title: '成交单价/购买数量',
            width: 150,
            className: 'ant-table-th-right',
            dataIndex: 'price-itemNumber',
            render: (value, record, index) => {
                return {
                    props: {
                        colSpan: 0
                    }
                }
            }
        },
        {
            title: type === 'unpay' ? '应付金额' : '实付金额',
            width: 130,
            className: "ant-table-th-center va-t",
            dataIndex: 'totalTradeCash',
            render: (value, record, index) => {
                return (
                    <div className="real-pay">
                        <p className="total-price">&yen;{(value || 0).toFixed(2)}</p>
                        <p className="freight">（含运费：&yen;{(record.logisticsFee || 0).toFixed(2)}）</p>
                        <p className="goods-num">共{record.itemOrders.reduce(((sum, item)=>sum + item.itemNumber), 0)}件</p>
                    </div>
                )
            }
        },
        {
            title: "发票信息",
            width: 160,
            className: "ant-table-th-center  va-t",
            dataIndex: "invoiceFlag",
            render: (value, record, index) => (<span>{!!value ? `需要发票（${record.invoiceType == 1 ? '普通发票' : '增值税发票'}）` : '不开发票'}</span>)
        }
    ]
}

